<?xml version="1.0" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lm="http://schemas.icitadel.com/Lazarus/Manifest.xsd" version="1.0">

	<xsl:output method="text"/>

	<xsl:include href="../../common.xsl" />
	<xsl:include href="../../convert.xsl" />

   <xsl:template match="lm:manifest">
		<xsl:variable name="ROOT_PATH" select="@output-path" />
		<xsl:variable name="FILTER_MASK">Database.StoredProcedure.Alter</xsl:variable>

		<xsl:variable name="DB_USER" select="lm:datasource/@user" />
		<xsl:variable name="DB_PASSWORD" select="lm:datasource/@password" />
		<xsl:variable name="DB_LOCATION" select="lm:datasource/@location" />
		<xsl:variable name="DB_SCHEMA" select="lm:datasource/@schema" />
		<xsl:text>#!/bin/bash

echo '</xsl:text><xsl:value-of select="@project-name" /><xsl:text>'
echo '-------------------------------------------------------------------------'
echo 'create_procs.sh'
echo 'Shell script to create all stored procedures in the database.'
echo ' '
echo ' '
echo 'Syntax: create_procs.sh [Instance] [Database]'
echo ' '

DEFAULT_INSTANCE='google.com:cloud-ta-test:perfkit'
DEFAULT_DATABASE='metrics_mart'

CheckInstance ()
{
  echo ' '
  echo 'Checking for specified Instance Name.'
  if [ $1 ]; then
    instance_name=$1
    echo 'Using default Instance '$1
  else
    instance_name=$DEFAULT_INSTANCE
  fi
}

CheckDatabase ()
{
  echo ' '
  echo 'Checking for specified Database.'
  if [ $2 ]; then
    database_name=$2
    echo 'Using default Database '$2
  else
    database_name=$DEFAULT_DATABASE
  fi
}

google_sql='sh /usr/local/google_sql_tool/google_sql.sh'

CheckInstance
CheckDatabase

</xsl:text>
		<xsl:for-each select="lm:files/lm:file[ starts-with( @type, $FILTER_MASK ) ]">
			<xsl:text>echo 'Compiling stored procedure "</xsl:text><xsl:value-of select="@concept-name" /><xsl:text>"'
</xsl:text>
			<xsl:text>$google_sql $instance_name $database_name &lt; </xsl:text>
			<xsl:value-of select="@name" />
			<xsl:text>

</xsl:text>
		</xsl:for-each>

   </xsl:template>

</xsl:stylesheet>